package jianzhi_offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class _21_从上往下打印二叉树 {
	public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
		ArrayList<Integer> res = new ArrayList<Integer>();
		if(root == null) return res;
		Queue<TreeNode> queue = new LinkedList<TreeNode>();
		queue.offer(root);
		while(!queue.isEmpty()) {
			TreeNode now = queue.poll();
			res.add(now.val);
			if(now.left != null) queue.offer(now.left);
			if(now.right!= null) queue.offer(now.right);
		}
		return res;
    }
}
